home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK2.toast / Development Kits (Disc 2) / QuickDraw™ GX / Programming Stuff / Sample Code / Graphics Samples / Caps Attached To a Curve ƒ / caps attached to a curve.c next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  4.3 KB  |  156 lines  |  [TEXT/KAHL]

  1. /*
  2.     caps attached to a curve.c 
  3.     
  4.     This file contains the calls to create a "thick" curve and attach a cap to each end of the
  5.     curve. 
  6.         
  7.     NOTES: 
  8.     • This file requires the following files to run correctly:
  9.         "graphics shell.c", "color library.c", "graphics debug library.c", "shape library.c", 
  10.         "transform library.c".
  11.         
  12.     • This file prints the "best" in landscape mode.
  13.  
  14.     ©1992 - 1994 Apple Computer, Inc. 
  15.     All rights reserved. 
  16. */
  17.  
  18.  
  19. #include <events.h>
  20. #include <windows.h>
  21.  
  22. #include "graphics debugging.h"
  23. #include "graphics libraries.h"
  24. #include "graphics toolbox.h"
  25. #include "graphics shell.h"
  26.  
  27. //
  28. //  Set up the title and size of the window 
  29. //
  30. Str255         gWindowTitle = "\p Caps Attached To a Curve";
  31. Rect         gWindowQDRect  = {50, 20, 275, 350};
  32.  
  33. //
  34. //    gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  35. //    in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  36. //    With  gGraphicsHeapSize set to 10k, I had 3 free blocks left in the graphics gxHeap. Sounds good to me.
  37. //
  38. long        gGraphicsHeapSize = 10;
  39.  
  40. gxShape     gShape;
  41. short        gClickNumber;
  42.  
  43.  
  44.  
  45. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  46.  
  47. void DoInitialization(gWindow)
  48. WindowPtr gWindow;
  49. {
  50.     gxCurve         curveGeometry = {ff(25), ff(125), ff(100), 0, ff(225), ff(125)};    
  51.     gxShape         arrowHead, arrowTail;
  52.     long            arrowHeadPolygonGeometry[] = {    4, // Number of points,
  53.                                                        -ff(2)-fixed1/2, 0,
  54.                                                         0, fixed1, 
  55.                                                          fixed1 + fixed1/2, 0, 
  56.                                                        0, -fixed1};
  57.                                                
  58.     long             arrowTailPolygonGeometry[] = {    5, // Number of points,
  59.                                                      -fixed1, 0, 
  60.                                                       0, fixed1, 
  61.                                                       ff(2), fixed1, 
  62.                                                       ff(2), -fixed1, 
  63.                                                       0, -fixed1};
  64.      gxCapRecord     theCapRecord;
  65.  
  66.      InitCommonColors();
  67.  
  68.     gShape = GXNewCurve (&curveGeometry);
  69.     
  70.     //
  71.     //    Create the cap shapes
  72.     //
  73.     arrowHead = NewPolygon((gxPolygon *) &arrowHeadPolygonGeometry);
  74.     arrowTail = NewPolygon((gxPolygon *) &arrowTailPolygonGeometry);
  75.  
  76.     //
  77.     //    We needed to reverse the direction of the contour to prevent a hole from being drawn
  78.     //    were the arrowHead or arrowTail capped the curve. This was an issue because the 
  79.     //    shape fill of the curve is openFrame and the arrowHead and arrowTail are evenOdd. 
  80.     //
  81.     GXReverseShape(arrowHead, 1);
  82.     GXReverseShape(arrowTail, 1);
  83.  
  84.     //
  85.     //    Add the appropriate shape for start cap and end cap
  86.     //
  87.     theCapRecord.startCap = arrowHead;
  88.     theCapRecord.endCap = arrowTail;
  89.     theCapRecord.attributes = gxNoAttributes;
  90.  
  91.     //
  92.     //    Add the cap record to our "gShape"
  93.     //
  94.     GXSetShapeCap(gShape, &theCapRecord);
  95.     
  96.     //
  97.     //    We do no need the cap shapes because they have been copied into the cap record which is
  98.     //    now part of the style used by "gShape".
  99.     //
  100.     GXDisposeShape(arrowHead);
  101.     GXDisposeShape(arrowTail);
  102.     
  103.     GXSetShapePen(gShape, ff(15));
  104.     SetShapeCommonColor(gShape, red);
  105.     GXMoveShape (gShape, ff(35), 0);
  106.     
  107.     gClickNumber = 1;
  108. }
  109.  
  110. /*------ DoClick ---------------------------------------------------------------------------------------*/
  111.  
  112. void DoClick( orgMouseLoc, theWindow )
  113. gxPoint        orgMouseLoc;
  114. WindowPtr     theWindow;
  115. {
  116. }
  117.  
  118.  
  119.  
  120.  
  121. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  122.  
  123. void DoDraw(gWindow)
  124. WindowPtr gWindow;
  125. {
  126.     GXDrawShape (gShape);
  127. }
  128.  
  129.  
  130. /*------ DoDispose -------------------------------------------------------------------------------------*/
  131.  
  132. void DoDispose(gWindow)
  133. WindowPtr gWindow;
  134. {
  135.     /**  
  136.         You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  137.         form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  138.         call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  139.         SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  140.         can turn notices on in this file by setting gDebugging = TRUE (above).
  141.     **/
  142.     GXDisposeShape(gShape);  
  143.      GXDisposeShape(gWindowBoundsShape);  
  144.        DisposeCommonColors();
  145.        DisposeWindow(gWindow);
  146. }
  147.     
  148.  
  149.  
  150. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  151.  
  152. void DoIdle(gWindow)
  153. WindowPtr gWindow;
  154. {
  155. }
  156.